package com.mgl.util;

import org.andengine.entity.scene.Scene;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.mgl.movesprite.EntitySpriteLevelBase;
import com.mgl.movesprite.game.factory.GameObjectFactory;
import com.mgl.movesprite.game.model.Level;

public class ButtonSprite extends EntitySpriteLevelBase {

	private ButtonSpriteListener buttonSpriteListener = null;

	public ButtonSprite(float pX, float pY, ITextureRegion pTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager,
			GameObjectFactory gameObjectFactory) {
		super(pX, pY, pTextureRegion, pVertexBufferObjectManager,
				gameObjectFactory);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void update(float pSecondsElapsed, Level level) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
			final float pTouchAreaLocalX, final float pTouchAreaLocalY) {

		// Toggle action
		switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			if (buttonSpriteListener != null) {
				buttonSpriteListener.onTouchDown();
			}
			break;
		case TouchEvent.ACTION_MOVE:
			if (buttonSpriteListener != null) {
				buttonSpriteListener.onTouchMove();
			}
			break;
		case TouchEvent.ACTION_UP:
			if (buttonSpriteListener != null) {
				buttonSpriteListener.onTouchUp();
			}
			break;
		}
		return true;
	}

	public ButtonSpriteListener getButtonSpriteListener() {
		return buttonSpriteListener;
	}

	public void setButtonSpriteListener(
			ButtonSpriteListener buttonSpriteListener) {
		this.buttonSpriteListener = buttonSpriteListener;
	}

	@Override
	public void detachFromScene(Scene scene) {
		scene.attachChild(this);
		
	}

	@Override
	public void attachToScene(Scene scene) {
		scene.attachChild(this);
		
	}
	
}
